import { Message } from 'element-ui'
import router from 'router/index.js'
const mutations = {
	//登录方法..
	login(state,payload){
		console.log('login')
		console.log(payload)
		state.userinfo    = payload.userinfo											//用户基本信息..
		// state.token         = 'this_is_a_sham_jwt'		//数据验证jwt
		state.role        = payload.role						//登陆者角色
		// state.operatorId  = payload.operatorId			//登陆者Id
		state.uid = payload.uid
		state.flag  	  = payload.flag			//flag
		state.goodModel   = payload.goodModel				//商品模型
		state.proCity     = payload.proCity					//城市信息
		state.outOperator = payload.outOperator			//用户信息
		state.username    = payload.name			//用户信息
	},
	//退出登录..
	logout(state){
		state.userinfo    = {}
		state.token         = ''
		state.menus       = []
		state.navigations = []
	},
	//关闭一个导航..
	closeone(state,payload){
		state.navigations.splice(payload,1)
	},
	//添加一个路由到导航..
	addItem(state,payload){
		let isHas = false
		state.navigations.forEach(item=>{
			if(item.path == payload.path){
				isHas = true
			}
		})
		if(state.navigations.length >10){
			Message({
				message: 'Tab数量达到上限,请先关闭部分Tab后使用',
				type:'error'
			})
			return;
		}
		if(!isHas){
			state.navigations.push(payload)
		}
	},
	//修改其他信息..
	otherinfo(state,payload){
		let city = '';
		payload.address.forEach(function(e){  
 			city = city + e
		});
		state.userinfo.email 			= payload.email
		state.userinfo.telephone 	= payload.telephone
		state.userinfo.address 	  = payload.address
		state.userinfo.avatar 		= payload.avatar
		state.userinfo.city 		  = city
	},

	//修改socket状态信息..
	changeSocketStatus(state,payload){
		state.socket_info.status = payload.status
		state.socket_info.errmsg = payload.errmsg
	},
	//修改重连次数..
	changeConnectTime(state){
		state.socket_info.connect_time++
	},
	updateGood(state,payload){
		state.goodModel   = payload				//商品模型
	}
}
export default mutations